﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MDS
{
    public class Exchange:EnumBase<char>
    {
        private static Dictionary<char, Exchange> _allExchange;
        
        private Exchange(char id):base(id) {  }

        static Exchange()
        {

            HuA = new Exchange('0');
            ShenA = new Exchange('1');
            HuB = new Exchange('2');
            ShenB = new Exchange('3');
            Future = new Exchange('F');
            _allExchange = new Dictionary<char, Exchange>();
            _allExchange.Add(HuA._value, HuA);
            _allExchange.Add(HuB._value, HuB);
            _allExchange.Add(ShenA._value, ShenA);
            _allExchange.Add(ShenB._value, ShenB);
            _allExchange.Add(FutureExchange.JinRong, Future);
            _allExchange.Add(FutureExchange.Dalian, Future);
            _allExchange.Add(FutureExchange.Shanghai, Future);
            _allExchange.Add(FutureExchange.Zhengzhou, Future);
        }

        public static bool TryParse(char exchId, out Exchange exchange)
        {
            if (_allExchange.ContainsKey(exchId))
            {
                exchange = _allExchange[exchId];
                return true;
            }
            else
            {
                exchange = default(Exchange);
                return false;
            }
        }
        public static bool TryParse(string exchIdStr, out Exchange exchange)
        {
            if (string.IsNullOrEmpty(exchIdStr))
            {
               char exchId= exchIdStr[0];
               return TryParse(exchId, out exchange);
            }
            else
            {
                exchange = default(Exchange);
                return false;
            }

        }
        public static Exchange HuA { get; private set; }
        public static Exchange ShenA { get; private set; }
        public static Exchange HuB { get; private set; }
        public static Exchange ShenB { get; private set; }
        public static Exchange Future { get; private set; }
    }
}
